/*
 * LDIR
 * 
 * LDIR, a GPS cartography application built for Let's Do It Romania eco 
 * campaign.
 * Copyright (C) 2010 Genera Software <office@generasoftware.com>
 * 
 * http://generasoftware.com/
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
#ifndef __WS_OBJECT_H__
#define __WS_OBJECT_H__

#include <e32base.h>
#include "Interfaces.h"
#include <Json.h>

/**
 *	\brief      Base class for all web service objects
 */
class CWsObject : public CBase, public MWsObject
	{
public:

	~CWsObject();
	static CWsObject* NewL();
	static CWsObject* NewLC();
	static CWsObject* NewL( CEntity* aEntity, TBool aOwnsEntity = ETrue );
	static CWsObject* NewLC( CEntity* aEntity, TBool aOwnsEntity = ETrue );
	HBufC8* EncodeL( CJsonGenerator& aJsonGenerator );
	void DecodeL( const TDesC8& aDesC, CJsonParser& aJsonParser );
	TInt GetIntAttribute( const TInt aAttrNameIndex, TInt& aValue );
	TInt GetRealAttribute( const TInt aAttrNameIndex, TReal& aValue );
	const TDesC& GetDesAttribute( const TInt aAttrNameIndex );
	const TDesC8& GetDes8Attribute( const TInt aAttrNameIndex );
	MWsObject* GetWsObjectL( const TInt aAttrNameIndex );
	TBool BoolAttribute( const TInt aAttrNameIndex );
	CEntity* GetEntity( const TInt aAttrNameIndex );
	void AddBoolAttributeL( const TInt aAttrNameIndex, const TBool aValue );
	void AddIntAttributeL( const TInt aAttrNameIndex, const TInt aValue );
	void AddRealAttributeL( const TInt aAttrNameIndex, const TReal aValue );
	void AddDesAttributeL( const TInt aAttrNameIndex, const TDesC& aValue );
	void AddDes8AttributeL( const TInt aAttrNameIndex, const TDesC8& aValue );
	// clones entity
	void AddEntityL( const TInt aAttrNameIndex, const CEntity& aEntity );
	// clones entity
	void AppendEntityL( const CEntity& aEntity );
	CEntity* Entity();

protected:

	void ConstructL();
	CWsObject();
	CWsObject( CEntity* aEntity, TBool aOwnsEntity );
	void ReadStreamDescL( const RReadStream& aReadStream, HBufC8*& aDesc );
	void
	WriteStreamDescL( RWriteStream& aWriteStream, const TDesC8& aDesc ) const;

protected:
	CEntity* iEntity;
	TBool iOwnsEntity;
	HBufC* iBuffer;
	};

#endif // __WS_OBJECT_H__
